<template>
  <div class="dashboard-editor-container">
    <el-card shadow="never">
      <el-row justify="space-between">
        <el-col :span="18" :xs="24">
          <div class="flex h-full items-center">
            <img
              class="w-20 h-20 mr-5 rounded-full"
              :src="userAvatar"
              alt="User Avatar"
            />
            <div>
              <p>{{ greetings }}</p>
              <p class="demo">今日天气晴朗，气温在15℃至25℃之间，东南风。</p>
            </div>
          </div>
        </el-col>

        <el-col :span="6" :xs="24" class="flex justify-between items-center">
          <el-row
            justify="space-between"
            class="w-full"
            style="margin-top: 10px"
          >
            <el-col :span="8">
              <el-statistic :value="99">
                <template #title>
                  <div class="flex items-center">
                    <svg-icon icon-class="message" size="20px" />
                    <span
                      class="text-[16px] ml-1 font-bold"
                      style="font-size: 20px"
                      >消息</span
                    >
                  </div>
                </template>
                <template #value="{ value }">
                  <span style="font-size: 20px">{{ value }}</span>
                </template>
              </el-statistic>
            </el-col>

            <el-col :span="8">
              <el-statistic :value="50">
                <template #title>
                  <div class="flex items-center">
                    <svg-icon
                      :icon-class="'todolist'"
                      size="20px"
                      style="width: 20px; height: 20px"
                    />
                    <span
                      class="text-[16px] ml-1 font-bold"
                      style="font-size: 20px"
                      >待办</span
                    >
                  </div>
                </template>
                <template #value="{ value }">
                  <span style="font-size: 20px">{{ value }}</span>
                </template>
                <template #suffix>
                  <span style="font-size: 20px">/100</span>
                </template>
              </el-statistic>
            </el-col>

            <el-col :span="8">
              <el-statistic :value="10">
                <template #title>
                  <div class="flex items-center">
                    <svg-icon icon-class="project" size="20px" />
                    <span
                      class="text-[16px] ml-1 font-bold"
                      style="font-size: 20px"
                      >项目</span
                    >
                  </div>
                </template>
                <template #value="{ value }">
                  <span style="font-size: 20px">{{ value }}</span>
                </template>
              </el-statistic>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-card>

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background: #fff; padding: 16px 16px 0; margin-bottom: 32px">
      <line-chart :chart-data="lineChartData" />
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <raddar-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <bar-chart />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from "./dashboard/PanelGroup";
import LineChart from "./dashboard/LineChart";
import RaddarChart from "./dashboard/RaddarChart";
import PieChart from "./dashboard/PieChart";
import BarChart from "./dashboard/BarChart";
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145],
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130],
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130],
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130],
  },
};

export default {
  name: "Index",
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
    };
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type];
    },
  },
  computed: {
    greetings() {
      const date = new Date();
      const hours = date.getHours();
      const user = this.$store.state.user;

      if (hours >= 6 && hours < 8) {
        return "晨起披衣出草堂，轩窗已自喜微凉🌅！";
      } else if (hours >= 8 && hours < 12) {
        return `上午好，${user.nickname}！`;
      } else if (hours >= 12 && hours < 18) {
        return `下午好，${user.nickname}！`;
      } else if (hours >= 18 && hours < 24) {
        return `晚上好，${user.nickname}！`;
      } else if (hours >= 0 && hours < 6) {
        return "偷偷向银河要了一把碎星，只等你闭上眼睛撒入你的梦中，晚安🌛！";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
